package com.stylefeng.guns.modular.customer.util;

import com.stylefeng.guns.core.datascope.DataScope;
import com.stylefeng.guns.core.shiro.ShiroKit;
import com.stylefeng.guns.core.util.SpringContextHolder;
import com.stylefeng.guns.modular.customer.dao.CustomerCompanyDao;
import com.stylefeng.guns.modular.system.model.CustomerCompany;
import org.apache.commons.collections.CollectionUtils;

import java.util.ArrayList;
import java.util.List;

public class DataScopeUtil {

    /**
     * 我负责的客户ids，数据范围
     * @return
     */
    public static DataScope getResponsibleScope() {

        List<Integer> result = new ArrayList<>();
        CustomerCompanyDao customerCompanyDao = SpringContextHolder.getBean(CustomerCompanyDao.class);
        List<CustomerCompany> customerCompanies = customerCompanyDao.selectBySalesmanId(ShiroKit.getUser().getId());
        if (CollectionUtils.isEmpty(customerCompanies)) {
            result.add(-1);
        }else{
            for (CustomerCompany c : customerCompanies) {
                result.add(c.getId());
            }
        }
        return new DataScope("customer_company_id",result);
    }

}
